package starter.kit.rx.app.feature.film;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import starter.kit.rx.app.R;
import starter.kit.rx.app.model.bean.top250.Subjects;
import starter.kit.rx.app.util.DisplayImgUtis;
import support.ui.adapters.EasyViewHolder;
import support.ui.utilities.ScreenUtils;

/**
 * ============================================================
 * 版权： xx有限公司 版权所有（c）2016
 * <p>
 * 作者：Loofer
 * 版本：1.0
 * 创建日期 ：2016/10/23 16:06.
 * 描述：豆瓣电影的viewholder
 * <p>
 * 注:如果您修改了本类请填写以下内容作为记录，如非本人操作劳烦通知，谢谢！！！
 * Modified Date Modify Content:
 * <p>
 * ==========================================================
 */

public class SubjectsViewHolder extends EasyViewHolder<Subjects> {

    @BindView(R.id.iv_film)
    ImageView iVFilm;
    @BindView(R.id.tv_film_name)
    TextView tvFilmName;
    @BindView(R.id.tv_film_grade)
    TextView tvFilmGrade;
    @BindView(R.id.ll_film_root)
    LinearLayout mLlFilmroot;
    private Context mContext;

    public SubjectsViewHolder(Context context, ViewGroup parent) {
        super(context, parent, R.layout.item_film_live);
        ButterKnife.bind(this, itemView);
        this.mContext = context;
    }

    @Override
    public void bindTo(int position, Subjects subjects) {

        if (!TextUtils.isEmpty("" + subjects.getRating().getAverage())) {
            tvFilmGrade.setText("评分:" + String.valueOf(subjects.getRating().getAverage()));
        } else {
            tvFilmGrade.setText("暂无评分");
        }
        //标题
        tvFilmName.setText(subjects.getTitle());
        //图片url
        ViewGroup.LayoutParams params = iVFilm.getLayoutParams();
        int width = ScreenUtils.getScreenWidth();
        int ivWidth = (width - ScreenUtils.dp2px(80, mContext)) / 3;
        params.width = ivWidth;
        double height = (420.0 / 300.0) * ivWidth;
        params.height = (int) height;
        iVFilm.setLayoutParams(params);
        if (subjects.getImages() != null && !TextUtils.isEmpty(subjects.getImages().getLarge())) {
            DisplayImgUtis.getInstance().display(mContext, subjects.getImages().getLarge(), iVFilm);
        }
        mLlFilmroot.setOnClickListener(v -> {
            Intent intent = new Intent(mContext, FilmDetailActivity.class);
            intent.putExtra(FilmDetailActivity.EXTRA_ID, subjects.identifier);
            mContext.startActivity(intent);
        });
    }

}
